package com.kpmg.datalake.common.controller;

import com.baomidou.mybatisplus.plugins.Page;
import com.kpmg.datalake.common.enums.ResultCodeEnum;
import com.kpmg.datalake.common.utils.LogUtils;
import com.kpmg.datalake.common.vo.OperationLogVO;
import com.kpmg.datalake.common.vo.ServerResponse;
import com.kpmg.datalake.operatelog.dto.OperationLogDTO;
import com.kpmg.datalake.operatelog.model.OperateLog;
import com.kpmg.datalake.operatelog.service.IOperateLogService;
import javax.annotation.Resource;
import org.springframework.beans.BeanUtils;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @Author: Richard.ji [richard.ji@kpmg.com]
 * @Date: 2018-08-23 16:02:31
 * @Description:  日志管理
 */
@RestController
@RequestMapping("/operationLog")
public class OperateLogController extends BaseController {
  @Resource
  private IOperateLogService operateLogService;

  /**
   * 获取日志列表
   * @return
   */
  @PostMapping(value = "/getOperationLogList")
  public ServerResponse<Page<OperateLog>> getOperationLogList(@RequestBody OperationLogVO operationLogVO){
    try {
      OperationLogDTO operationLogDTO = new OperationLogDTO();
      BeanUtils.copyProperties(operationLogVO, operationLogDTO);

      Page<OperateLog> operateLogList = operateLogService.getOperationLogList(operationLogDTO);

      return doSuccess(operateLogList);
    } catch (Exception e) {
      LogUtils.error("获取日志列表失败", e);
      return doError(ResultCodeEnum.CODE4015, ResultCodeEnum.CODE4015.getDisplay());
    }
  }
}

